<template>
    <div v-if="worksInfo.length != 0">
        <el-row class="swiper-painter-item">
            <el-card class="swiper-painter-cards" v-for="(workInfo,index) in worksInfo" :key="index">
                <button class="work-button" style="border: #ffffff">
                    <div v-if="workInfo.workFileType === 1"  @click="workDetail(workInfo)">
                        <img class="image" :src="imgUrl+workInfo.workFilename"/>
                    </div>
                    <div @click="workDetail(workInfo)" v-else>
                        <video :poster="workInfo.poster" :controls="true" class="video_fo" :src="imgUrl+workInfo.workFilename"></video>
                    </div>
                </button>
                    <div class="work-div">
                            <span class="painter-item-name">
                                {{workInfo.workName}}
                            </span>
                    </div>

                    <div class="introduction-motto">
                        <span class="author-span">
                            <img class="work-user-img" :src="imgUrl+workInfo.userImg">
                            <span class="author-span">
                                {{workInfo.username}}
                            </span>
                        </span>
                        <span class="star-span">
                            <i class="icon-favorites"></i>
                            {{workInfo.workLikesNums}}
                        </span>
                    </div>

            </el-card>
        </el-row>
        <!--页码-->
        <section class="stage-flex-container"
                 style="justify-content: center; align-items: stretch; align-self: auto;">
            <div class="is-darken el-pagination is-background">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :total="worksInfo.length">
                </el-pagination>
            </div>
        </section>
    </div>
</template>

<script setup>
  import {getWorkInfoByKeyWord} from "@/assets/api/workInfoApi";
  import {useRoute, useRouter} from "vue-router";
  import {getCurrentInstance, onBeforeMount, ref} from "vue";

  const searchText = route.query.searchText;
  const worksInfo = ref([{}]);
  const centerDialogVisible = ref(false);
  const workImg = ref('');
  const workInfo = ref({});
  const comments = ref([]);
  const comment = ref('');
  const route = useRoute();
  const router = useRouter();
  const imgUrl = getCurrentInstance()?.appContext.config.globalProperties.$imgUrl

  const getWorksInfo = () => {
    searchText.value = route.query.searchText;
    router.push({path: route.path, query: {searchText: searchText, type: 'work_likes_nums'}});
    let data = {};
    data.workName = route.query.searchText;
    getWorkInfoByKeyWord(route.query.type, data).then((res) => {
      worksInfo.value = res.data.data;
    })
  };
  const workDetail = (work) => {
    router.push({path: '/workDetail', query: {id: work.workId}});
  };

  // watch:{
  //     '$route' (to, from){
  //         getWorksInfo();
  //     }
  // },
  onBeforeMount(() => {
    getWorksInfo();
  });
</script>

<style scoped>
    @import "../../assets/fonts/iconfont.css";
    .swiper-painter-item {
        overflow: hidden;
        border-radius: 4px;
        display: flex;
        flex-wrap: wrap;
    }
    .swiper-painter-cards {
        margin-top: 15px;
        height: 400px;
        margin-right: 10px;
        width: 300px;
    }
    .painter-item-name {
        max-width: 100px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        align-items: center;
        font-size: 14px;
        color: #333;
    }
    .introduction-motto {
        background-color: #ffffff;
        margin-top: 8px;
        font-size: 14px;
        word-break: break-all;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: justify;
        text-justify: inter-ideograph;
    }
    .image {
        width: 100%;
        height: 250px;
        display: block;
        margin: 0 auto
    }
    .container {
        width: 1200px;
        margin: 0 auto;
    }
    p {
        display: block;
        margin-block-start: 1em;
        margin-block-end: 1em;
        margin-inline-start: 0px;
        margin-inline-end: 0px;
    }
    .position {
        text-decoration: none;
        color: #222222;
    }
    .position:hover {
        color: #adb3fb;
    }
    .star-span {
        color: #adb3fb;
        float: right;
        background-color: #ffffff;
        margin-top: 20px;
    }
    .author-span {
        color: #777;
        font-size: 14px;
        max-width: 154px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        background-color: #ffffff;
    }
    .work-user-img {
        width: 55px;
        height: 55px;
        border-radius: 100%;
    }
    .work-div {
        background-color: #ffffff;
        margin-top: 20px;
        text-align: center;
    }
    .work-button {
        background-color: #ffffff;
        border: #fff;
        text-align: center;
    }
    .panel img {
        width: 300px;
        height: 400px;
        padding: 70px;
    }
    .works-detail {
        width: 1200px;
        margin: 0 auto;
    }
    .works-panel {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: flex-start;
        float: left;
    }
    /deep/ .el-dialog {
        display: flex;
        flex: 1;
        background-color: transparent;
        box-shadow: unset;
        position: static;
        width: auto;
        border-radius: 4px;
    }
    /deep/ .el-dialog__header {
        padding: 30px 30px 10px;
    }
    /deep/ .el-dialog__body {
        justify-content: center;
        align-items: center;
        display: flex;
        flex: 1;
        padding: 20px 30px 30px;
        color: #4a4a4a;
        font-size: 14px;
        word-break: break-all;
    }
    .work-img {
        float: left;
        text-align: left;
        font-size: 14px;
        color: #4a4a4a;
        margin-bottom: 15px;
        width: 70%;
        margin-left: 154px;
    }
    .dialog {
        z-index: 1000;
    }
    .artwork-modal__modal {
        position: relative;
        width: 950px;
        height: auto;
        border-radius: 8px;
        margin: auto;
    }
    .modal-author {
        padding: 20px 30px;
        margin-bottom: 20px;
        border-radius: 4px;
        background: #fff;
        display: flex;
        justify-content: space-between;
    }
    .stage-flex-container {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
    }
    .avatar-wrapper {
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        transition: .5s;
        box-sizing: content-box;
    }
    .avatar-wrapper__img-wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
    }
    .avatar-wrapper.is-round .avatar-wrapper__img-wrapper, .avatar-wrapper.is-round img {
        border-radius: 100%;
    }
    .avatar-wrapper__avatar.border {
        border: 1px solid transparent;
    }
    .avatar-wrapper__avatar {
        width: 100%;
        opacity: 1;
    }
    .modal-author__author-info {
        display: flex;
        width: auto;
        flex: 0 0 auto;
        flex-direction: column;
        justify-content: center;
        color: #707070;
    }
    .modal-author__author-credit {
        margin-top: 5px;
        display: inline-block;
    }
    .el-rate {
        height: 20px;
        line-height: 1;
    }
    .el-rate__item {
        font-size: 0;
        vertical-align: middle;
    }
    .stage-flex-container {
        display: flex;
    }
    .modal-author__author-operator button {
        margin-left: 15px;
        width: 94px;
        height: 30px;
        padding: 4px 15px;
        border-radius: 20px;
        border: 1px solid transparent;
    }
    .stage-button--warning {
        color: #fff;
        background-color: #adb3fb;
        border-color: #9eb0fb;
    }
    .stage-button--small {
        padding: 7px 18px;
        font-size: 12px;
        border-radius: 4px;
    }
    .stage-button {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        border: 1px solid #dcdfe6;
        appearance: none;
        text-align: center;
        outline: none;
        margin: 0;
        transition: .1s;
        user-select: none;
        padding: 10px 24px;
        font-size: 14px;
        border-radius: 4px;
    }
    a {
        text-decoration: none;
    }
    .author-p {
        color: #222222;
    }
    .artwork-modal__artwork-img {
        border-top-left-radius: 4px;
    }
    .stage-img {
        position: relative;
    }
    .stage-img__hover-shade {
        opacity: 0;
        pointer-events: none;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        background: #fff;
        background: hsla(0, 0%, 100%, .2);
        transition: .5s;
    }
    .artwork-modal__artwork-img-wrapper img {
        width: 100%;
        cursor: pointer;
        border-top-left-radius: 4px;
    }
    .artwork-modal__artwork {
        background: #fff;
        display: flex;
        flex-direction: column;
        border-radius: 4px;
        position: relative;
    }
    .stage-img__img.is-hoverable {
        cursor: pointer;
    }
    .stage-img__img.is-responsive {
        max-width: 100%;
        display: flex;
        flex: none;
        margin: 0 auto;
        width: 950px;
    }
    .stage-img__img {
        display: block;
    }
    .artwork-modal__sidebar {
        padding: 20px 30px 30px;
        border-top: 1px solid #ececec;
    }
    .artwork-modal__copyright-tips {
        display: flex;
        justify-content: space-between;
        padding-bottom: 20px;
        border-bottom: 1px solid #ececec;
        margin-bottom: 20px;
        font-size: 12px;
        color: #9b9b9b;
    }
    .artwork-modal__created-at {
        padding-right: 10px;
        margin-right: 10px;
        position: relative;
    }
    .artwork-modal__tag-more-artwork-wrapper {
        display: flex;
        -ms-flex: 1;
        flex: 1;
        position: relative;
        flex-direction: column;
        align-items: stretch;
    }
    .stage-flex-container {
        display: flex;
    }
    .stage-flex-container.is-vertical {
        flex-direction: column;
    }
    .artwork-modal__sidebar-title {
        color: #9b9b9b;
        font-size: 14px;
        line-height: 14px;
        margin-bottom: 10px;
    }
    .artwork-modal ul {
        padding-left: 0;
        list-style: none;
    }
    .artwork-modal li {
        display: inline-block;
    }
    .category-tag {
        color: #222222;
        padding: 0px 10px;
        font-size: 12px;
        border: 1px solid #adb3fb;
        border-radius: 40px;
        margin: 5px 5px 5px 5px;
        transition: .5s;
        cursor: pointer;
    }
    /deep/ .el-dialog__headerbtn {
        position: fixed;
        top: 20px;
        right: 40px;
        padding: 0;
        background: 0 0;
        border: none;
        cursor: pointer;
        font-size: 60px;
        color: #222222;
    }
    .works-comment {
        margin-top: 14px;
        padding: 24px 28px;
        background-color: #fff;
        border-radius: 4px;
    }
    .comment-form {
        display: flex;
    }
    .clearfix {
        zoom: 1;
    }
    .comment-text {
        outline: none;
        flex-grow: 1;
        height: 40px;
        background: #fff;
        border-radius: 4px 0 0 4px;
        padding: 12px;
        font-size: 14px;
        border: 1px solid #eee;
        overflow: hidden;
        resize: none;
    }
    .comment-btn {
        cursor: pointer;
        width: 116px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        background: #adb3fb;
        border-radius: 0 4px 4px 0;
        color: #2d2d2d;
        font-size: 18px;
    }
    .comment-num {
        font-size: 16px;
        color: #1a1a1a;
        padding: 20px 0;
    }
    .comment-num span {
        color: #999;
        font-size: 14px;
    }
    .comment-li {
        display: flex;
        margin-bottom: 20px;
    }
    .user-avatar {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        flex-shrink: 0;
    }
    .c-face-img-con {
        display: inline-block;
        position: relative;
    }
    .c-face-img img {
        width: 100%;
        height: 100%;
    }
    .comment-wrap {
        flex: 1;
        margin-left: 20px;
        border-bottom: 1px solid #eee;
        padding-bottom: 20px;
    }
    .user-name {
        font-weight: 700;
        color: #333;
        font-size: 14px;
    }
    .user-content {
        margin-top: 8px;
        color: #666;
        font-size: 14px;
        word-break: break-all;
    }
    .comment-info {
        padding: 14px 0 0;
        color: #999;
        font-size: 12px;
        display: flex;
    }
    .comment-time {
        flex-grow: 1;
    }
    .like-num {
        cursor: pointer;
        position: relative;
        display: flex;
        align-items: center;
    }
    .like-num span {
        margin-bottom: 2px;
        display: inline-block;
    }
    .artwork-modal__operator {
        position: absolute;
        left: 100%;
        width: 80px;
        height: 80px;
        font-size: 14px;
        background: #fff;
        border-radius: 0 8px 8px 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        line-height: 1;
        color: #9b9b9b;
    }
    .artwork-modal__operator i {
        color: #d8d8d8;
        font-size: 32px;
        margin-bottom: 5px;
    }
</style>
